export default function localStoragePlugin(storageKey = 'clearusdt14') {
    return store => {
        // 页面加载时，先从 localStorage 中获取
        const savedState = localStorage.getItem(storageKey)
        if (savedState) {
            try {
                store.replaceState(JSON.parse(savedState))
            } catch (error) {
                console.error('Error parsing stored state:', error)
            }
        }

        // 监听所有 mutation，每次 mutation 都存一次 localStorage
        store.subscribe((mutation, state) => {
            localStorage.setItem(storageKey, JSON.stringify(state))
        })
    }
}